home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snip1292.zip / DIRMASK.C < prev    next >
C/C++ Source or Header  |  1992-12-26  |  3KB  |  74 lines

  1. /*
  2. **  DIRMASK.C - Complex pattern matching
  3. **
  4. **  Original Copyright 1988-1991 by Bob Stout as part of
  5. **  the MicroFirm Function Library (MFL)
  6. **
  7. **  This subset version is functionally identical to the
  8. **  version originally published by the author in Tech Specialist
  9. **  magazine and is hereby donated to the public domain.
  10. */
  11.  
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include "dirent.h"
  15.  
  16. int patmat(const char *, const char *);
  17.  
  18. typedef enum {ERROR = -1, FALSE, TRUE} LOGICAL;
  19. #define SUCCESS 0
  20.  
  21. /****************************************************************/
  22. /*                                                              */
  23. /*  dirmask()                                                   */
  24. /*                                                              */
  25. /*  Tests a directory entry for matching patterns. Tests both   */
  26. /*  file name and attributes. Tests for both inclusion specs    */
  27. /*  and exclusion specs.                                        */
  28. /*                                                              */
  29. /*  Parameters: 1 - Pointer to the directory entry's FIND       */
  30. /*                  structure                                   */
  31. /*              2 - Filename for inclusion matching, i.e. if    */
  32. /*                  this spec matches the filename, we matched. */
  33. /*                  Use NULL to match anything.                 */
  34. /*              3 - Filename for exclusion matching, i.e. if    */
  35. /*                  this spec matches the filename, we failed.  */
  36. /*                  Use NULL to exclude nothing.                */
  37. /*              4 - Attribute for inclusion mask. Use FA_ANY    */
  38. /*                  to match anything).                         */
  39. /*              5 - Attribute for exclusion mask. Use zero to   */
  40. /*                  exclude nothing).                           */
  41. /*                                                              */
  42. /*  Returns: SUCCESS if name and attribute matched, else ERROR. */
  43. /*                                                              */
  44. /*  Side effects: Converts patterns to upper case               */
  45. /*                                                              */
  46. /****************************************************************/
  47.  
  48. int dirmask(struct DSTRUCT *dstruct,
  49.             char           *fname_inc,
  50.             char           *fname_exc,
  51.             unsigned        attr_inc,
  52.             unsigned        attr_exc)
  53. {
  54.       if (!dstruct)
  55.             return ERROR;
  56.       strupr(fname_inc);
  57.       strupr(fname_exc);
  58.       if (fname_inc)
  59.       {
  60.             if (TRUE != patmat(dstruct->NAME, fname_inc))
  61.                   return ERROR;
  62.       }
  63.       if (fname_exc)
  64.       {
  65.             if (TRUE == patmat(dstruct->NAME, fname_exc))
  66.                   return ERROR;
  67.       }
  68.       if (!((dstruct->ATTRIBUTE | 0x80) & attr_inc))
  69.             return ERROR;
  70.       if (dstruct->ATTRIBUTE & attr_exc)
  71.             return ERROR;
  72.       return SUCCESS;
  73. }
  74.